home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d11 / egafast.arc / EGAFAST1 next >
Encoding:
Internet Message Format  |  1988-04-17  |  35.3 KB

  1. Path: marob!mancol!manhat!phri!cmcl2!nrl-cmf!ames!necntc!ncoast!allbery
  2. From: mcdonald@uxe.cso.uiuc.edu (J.D. McDonald )
  3. Newsgroups: comp.sources.misc
  4. Subject: v02i022: EGAFAST IBM-PC Graphics Package, Part 1/2
  5. Message-ID: <7133@ncoast.UUCP>
  6. Date: 26 Jan 88 04:27:34 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Lines: 1342
  9. Approved: allbery@ncoast.UUCP
  10. X-Archive: comp.sources.misc/egafast/1
  11. Comp.sources.misc: Volume 2, Issue 22
  12. Submitted-By: J.D. McDonald <mcdonals@uxe.cso.uiuc.edu>
  13. Archive-Name: egafast/Part1
  14.  
  15. Comp.sources.misc: Volume 2, Issue 22
  16. Submitted-By: J.D. McDonald <mcdonals@uxe.cso.uiuc.edu>
  17. Archive-Name: egafast/Part1
  18.  
  19. [I am sending this person a complimentary "shar" program.  I can post it as
  20. is or spend the next 6 months trying to take the two files apart... guess
  21. which I chose.  The author takes his chances with its making it over the
  22. net.  ++bsa]
  23.  
  24. due to the size, distribution is in two parts
  25. This is part one.
  26.  
  27.  
  28. *********begin file READ.ME*************
  29. This is a very simple graphics package for the EGA and VGA. It draws the
  30. basic primitives of lines, ellipses, filled rectangles, filled ellipses,
  31. and text (two sizes and user defined). It is written to get the ultimate
  32. in high speed possible while drawing in the set/reset mode. It can be
  33. called from Microsoft C and Fortran, or any language including assembler
  34. which follows their calling conventions.
  35. Here is a list of the included files:
  36.  
  37. CLIPLINE C     Source code for clipped line routine.
  38. EGAFORT  H     Header file for subroutine prototypes for Fortran.
  39. EGAGRA   ASM   The main graphics package source.
  40. EGAGRA   DOC   Documentation.
  41. EGATEST  C     A test program to verify correct compilation.
  42. ELLIPSE  C     Source code for ellipse drawers.
  43. GRAFEX1  C     Example program that draws a star.
  44. GRAFEX2  C     Example program that uses user-defined patterns.
  45. INTEST   ASM   Assembler subroutine for SLUGS.FOR
  46. MACROS   AH    Header file for EGAGRA.ASM which defines memory model.
  47. MOVERM   C     Example program for plane masking.
  48. MOVERS   C     Example program for page swapping and plane masking.
  49. SLUGS    FOR   Example program in Fortran whose results look nice.
  50.  
  51. Some of the code in this package is patterned after that of U.E.Kruse of
  52. the U. of I. Physics department. The grafex1 demo program generates
  53. essentially the same pattern as the one of the same name in the package
  54. by Scott Snyder of caltech recently posted on the net. The macros.ah
  55. is also from his package.
  56.  
  57. Your comments are welcome, especially if you see anything faster.
  58.  
  59. Doug McDonald
  60. University of Illinois
  61. 505 S. Matthews 
  62. Urbana Ill. 61801
  63. (mcdonald@uiucuxe or mcdonald@uxe.cso.uiuc.edu)
  64.  
  65.  
  66. ***********end file READ.ME***********
  67. ***********begin file EGAGRA.ASM************
  68. include macros.ah
  69.  
  70. _DATA   segment  word public 'DATA'
  71. first8  dw       0
  72. first14 dw       0
  73. drawseg dw      0A000h
  74. maxseg  dw      28000
  75. maxline dw      350
  76. _DATA   ends
  77. CONST   segment  word public 'CONST'
  78. ate     dw       8
  79. fourt   dw       14
  80. eighty  dw       80
  81. btab    db       80h,40h,20h,10h,8h,4h,2h,1h
  82. left    db       255,127,63,31,15,7,3,1
  83. right   db       128,192,224,240,248,252,254,255
  84. CONST   ends
  85. _BSS    segment  word public 'BSS'
  86. es8       dw        ?
  87. bp8       dw        ?
  88. es14      dw        ?
  89. bp14      dw        ?      
  90. leftbit   db        ?
  91. rightbit  db        ?
  92. lefttop   dw        ?
  93. leftbot   dw        ?
  94. righttop  dw        ?
  95. rightbot  dw        ?
  96. ysave     dw        ?
  97. leftx     dw        ?
  98. rightx    dw        ?
  99. xx0       dw        ?
  100. yy0       dw        ?
  101. xx1       dw        ?
  102. yy1       dw        ?
  103. xc10      dw        ?
  104. xc20      dw        ?
  105. xc11      dw        ?
  106. xc21      dw        ?
  107. lowyb     dw        ?
  108. del_y     dw        ?
  109. del_x     dw        ?
  110. _BSS      ends
  111. DGROUP  GROUP    CONST, _BSS, _DATA
  112.          assume   ds: DGROUP, ss: DGROUP, es:  DGROUP
  113. cseg    _egagraf
  114.  
  115. ;The code in this program has been optimized for speed, not readibility.
  116. ;As much as possible is put into registers. Replication of large blocks
  117. ;of code has been used in some places to avoid calling subroutines.
  118.  
  119. pBegin  _symbol
  120. ;  symbol(ix,iy,height,icol,&isym) plots a single 8xheight character  
  121. ;  matrix pointed to by isym at ix, iy in color icol. 
  122. ;  ix, iy and icol are integers 
  123.         push    bp
  124.         mov     bp,sp
  125.         push    di
  126.         push    si
  127. ifdef NEARDATA
  128.         mov     si, word ptr [bp+argbase+12]   ;pick up address of table
  129.         mov     bx,ds                          ;containing symbol to plot
  130.         mov     es,bx
  131. endif
  132. ifdef FARDATA
  133.         les     si,[bp+argbase+12]
  134. endif
  135.         mov     bx,word ptr [bp+argbase+8]      ;height
  136.         mov     ax,word ptr [bp+argbase+4]      ;this is x
  137.         mov     dx,ax                ;break x into byte # and bit in byte
  138.         and     dx,7
  139.         mov     cl,3
  140.         sar     ax,cl
  141.         mov     [bp+argbase+8],ax    ;byte #
  142.         mov     [bp+argbase+4],dx    ;leftmost bit used   
  143.         mov     dx,drawseg       ; segment of display buffer
  144.         push    ds
  145.         mov     ax,es             
  146.         mov     es,dx
  147.         mov     ds,ax               
  148.         jmp     commonl
  149.  
  150. pEnd _symbol
  151.  
  152.  
  153. pBegin _slettr
  154. ;  slettr(ix,iy,ichr,icol) plots a single 8-high IBM character ichr at x,y in 
  155. ;  color icol.   all are integers
  156.         push    bp
  157.         mov     bp,sp
  158.         push    di
  159.         push    si
  160.         cmp     first8,0        ;get address of bios table of characters
  161.         jne     sec8
  162.         inc     first8          ;done only first time this routine is called
  163.         mov     ah, 011h
  164.         mov     al, 030h
  165.         mov     bh, 03
  166.         push    bp              ;(gasp)Bios call destroys BP
  167.         int     010h
  168.         mov     ax,es
  169.         mov     es8,ax
  170.         mov     bp8,bp
  171.         pop     bp
  172. sec8:
  173.         xor     ax,ax
  174.         mov     al,byte ptr [bp+argbase+8]   ;this is the character
  175.                                 ;look up location of ascii characters
  176.         mov     cl,3
  177.         shl     ax,cl            ;in bios 
  178.         add     ax,bp8             
  179.         mov     si,ax              
  180.         mov     ax,word ptr [bp+argbase+4]      ;this is x
  181.         mov     dx,ax
  182.         and     dx,7             ;break into bit and byte
  183.         mov     cl,3
  184.         sar     ax,cl
  185.         mov     [bp+argbase+8],ax  ;byte #
  186.         mov     [bp+argbase+4],dx  ;bit in byte     
  187.         mov     ax,drawseg       ; segment of display buffer
  188.         mov     es,ax               
  189.         push    ds
  190.         mov     ax,es8          ; segment for bios reference
  191.         mov     ds,ax           ; used to 
  192.         mov     bx,8            ;find character
  193.         jmp     commonl
  194.  
  195. pEnd _slettr
  196.  
  197.  
  198. pBegin _llettr
  199. ; llettr(ix,iy,ichr,icol) plots a single IBM 14-high character ichr at x,y in 
  200. ; color icol.   all are integers
  201.         push    bp
  202.         mov     bp,sp
  203.         push    di
  204.         push    si
  205.  
  206.         cmp     first14,0       ;works just like slettr : done again for speed
  207.         jne     sec14
  208.         inc     first14
  209.         mov     ah, 011h
  210.         mov     al, 030h
  211.         mov     bh, 02
  212.         push    bp
  213.         int     010h
  214.         mov     ax,es
  215.         mov     es14,ax
  216.         mov     bp14,bp
  217.         pop     bp
  218. sec14:
  219.  
  220.         xor     ax,ax
  221.         mov     al,byte ptr [bp+argbase+8]    
  222.         mul     fourt        
  223.         add     ax,bp14           
  224.         mov     si,ax              
  225.         mov     ax,word ptr [bp+argbase+4]  
  226.         mov     dx,ax
  227.         and     dx,7
  228.         mov     cl,3
  229.         sar     ax,cl
  230.         mov     [bp+argbase+8],ax
  231.         mov     [bp+argbase+4],dx              
  232.  
  233.         mov     ax,drawseg     
  234.         mov     es,ax               
  235.         push    ds
  236.         mov     ax,es14       
  237.         mov     ds,ax      
  238.         mov     bx,14       
  239.  
  240.  
  241. commonl:
  242.                               ; symbol, slettr, and llettr the same after this
  243.                               ; compute location of byte to change
  244.         mov     ax,word ptr [bp+argbase+6]         ;this is y
  245.         mov     dx,ax
  246.         shl     dx,1
  247.         shl     dx,1
  248.         add     ax,dx
  249.         mov     cl,4
  250.         shl     ax,cl
  251.         add     ax,[bp+argbase+8]               ;this is horiz byte number
  252.         mov     di,ax
  253.  
  254.         mov     dx,3ceh         ; change SET/RESET register
  255.         mov     al,00h          ; to contain the color to write.
  256.         out     dx,al
  257.         mov     dx,3cfh
  258.         mov     ax,word ptr [bp+argbase+10]     ; <-- color
  259.         out     dx,al
  260.  
  261.         mov     dx,3ceh         ;point controller to bit mask register
  262.         mov     al,08h
  263.         out     dx,al
  264.         mov     dx,3cfh
  265.         cmp     word ptr [bp+argbase+8],0ffffh  ;special case:partially off
  266.                                                 ;left edge of screen
  267.         je      loop2m1
  268.         cmp     word ptr [bp+argbase+8],79      ;Partially off right edge
  269.         je      loop2p1
  270.         cmp     word ptr [bp+argbase+8],80  ;totally off screen horizontally
  271.         jae     commf
  272. loop2:
  273.  
  274.         xor     ax,ax
  275.         mov     ah,ds:[si+0]            ;get pattern of current row
  276.         mov     cx,[bp+argbase+4]
  277.         shr     ax,cl                   ;shr to get two bytes
  278.         out     dx,al    
  279.         inc     byte ptr es:[di+1]      ;actual screen write
  280.         mov     al,ah
  281.         out     dx,al
  282.         inc     byte ptr es:[di]        ;write second byte
  283.         add     di,80                   ;next row
  284.         inc     si
  285.         dec     bx
  286.         jg      loop2
  287.         jmp     commf
  288. loop2m1:
  289.  
  290.         xor     ax,ax                   ;leftmost byte is off screen
  291.         mov     ah,ds:[si+0]            ;get current row pattern
  292.         mov     cx,[bp+argbase+4]
  293.         shr     ax,cl                   ;shr to get two bytes
  294.         out     dx,al    
  295.         inc     byte ptr es:[di+1]      ;actual screen write
  296.         add     di,80
  297.         inc     si
  298.         dec     bx
  299.         jg      loop2m1
  300.         jmp     commf
  301. loop2p1:
  302.  
  303.         xor     ax,ax                  ;rightmost byte is off screen
  304.         mov     ah,ds:[si+0]           ;get current row pattern
  305.         mov     cx,[bp+argbase+4]
  306.         shr     ax,cl                  ;shr to get two bytes
  307.         mov     al,ah
  308.         out     dx,al
  309.         inc     byte ptr es:[di]
  310.         add     di,80
  311.         inc     si
  312.         dec     bx
  313.         jg      loop2p1
  314.  
  315. commf:
  316.         pop     ds
  317.         pop     si
  318.         pop     di
  319.         pop     bp
  320.         ret
  321.  
  322. pEnd _llettr
  323.  
  324. pBegin _max_lin
  325.         mov     ax,maxline
  326.         ret
  327. pEnd   _max_lin
  328.  
  329. ; setmod.asm routine to be called from c to set mode n using
  330. ; call setmod(n) : n=3 set to cursor mode, n=16 set to color graphics mode
  331. ; n = 15 for bw graphics mode, 18 for VGA 480x640 color mode 
  332.  
  333. pBegin _setmod
  334.  
  335.         push    bp
  336.         mov     bp,sp
  337.  
  338.         mov     ax, word ptr [bp+argbase+4]     
  339.         mov     maxseg,28000
  340.         mov     maxline,350
  341.         cmp     ax,18
  342.         jnz     setm1
  343.         mov     maxseg,38400
  344.         mov     maxline,480
  345. setm1:
  346.         int     10H
  347.         pop     bp              
  348.         ret
  349.  
  350. pEnd _setmod
  351.  
  352. pBegin _zsetup
  353.         push    dx
  354.         push    ax
  355.  
  356.         mov     dx,3c4h         ; allow writing to all planes
  357.         mov     al,02h          ; can be changed by setmask
  358.         out     dx,al
  359.         mov     dx,3c5h
  360.         mov     al,0fh
  361.         out     dx,al
  362.  
  363.         mov     dx,3ceh         ; change ENABLE SET/RESET register
  364.         mov     al,01h          ; to use SET/RESET feature
  365.         out     dx,al
  366.         mov     dx,3cfh
  367.         mov     al,0fh
  368.         out     dx,al
  369.         pop     ax
  370.         pop     dx
  371.         ret
  372. pEnd _zsetup
  373.  
  374. ; ZLINE  :  SUBROUTINE TO DRAW LINE ON EGA BOARD
  375. ;this version has microsoft c calling convention
  376. ;      zline(ix0,iy0,ix1,iy1,icolor)
  377. pBegin _zline 
  378.         push    bp
  379.         mov     bp,sp
  380.         mov     cx,word ptr [bp+argbase+6]      ;cx has first y
  381.         cmp     cx,word ptr [bp+argbase+10]     ;compare with last y
  382.         jne     nhoriz
  383.         jmp     far ptr __horiz_
  384. nhoriz:
  385.         sub     sp,6
  386.         push    di
  387.         push    si 
  388.         mov     dx,3ceh      ;set up color register
  389.         mov     al,00h
  390.         out     dx,al
  391.         mov     dx,3cfh
  392.         mov     ax,word ptr [bp+argbase+12]     ;this is color
  393.         out     dx,al
  394.  
  395.         mov     dx,word ptr [bp+argbase+10]     ;dx has last y
  396.         mov     ax,word ptr [bp+argbase+8]
  397.         mov     di,ax                           ;di has last x
  398.         mov     bx,word ptr [bp+argbase+4]      ;bx has first x 
  399.         mov     ax,di
  400.         sub     ax,bx           
  401.         jge     store_x
  402.         mov     bx,di           
  403.         mov     di,dx           ;make sure line goes from lower to higher x
  404.         mov     dx,cx
  405.         mov     cx,di
  406.         neg     ax
  407. store_x: 
  408.         mov     word ptr[bp+argbase+6],ax
  409.         mov     word ptr[bp+argbase+4],bx        ;store new first point
  410.         mov     word ptr[bp+argbase+8],cx
  411.         sub     dx,cx
  412.         mov     word ptr [bp-2],80 ;put increment for pointer in screen buffer
  413.         jge     store_y         ;into temporary
  414.         neg     word ptr [bp-2]
  415.         neg     dx
  416. store_y:
  417.         mov     word ptr[bp+argbase+10],dx
  418. ;initialize values
  419.         mov     dx,3ceh         ;prepare register for changing pixel
  420.         mov     al,08h
  421.         out     dx,al
  422.         mov     ax,drawseg       ;load start of screen buffer in es  
  423.         mov     es,ax
  424. ;calculate address in screen buffer of first point
  425.         mov     ax,word ptr[bp+argbase+4]
  426.         mov     dx,ax
  427.         and     dx,7
  428.         mov     cl,3
  429.         sar     ax,cl
  430.         mov     si,ax      ;load initial x byte offset into si
  431.         lea     bx,btab
  432.         add     bx,dx      ;[bx] has a 1 in bit of first point 
  433.         mov     ax,word ptr[bp+argbase+8]   ; mul by first y
  434.         mov     dx,ax
  435.         shl     dx,1
  436.         shl     dx,1
  437.         add     ax,dx
  438.         mov     cl,4
  439.         shl     ax,cl
  440.         mov     dx,ax
  441.         mov     al,[bx]         ;al has pointer in byte for exact bits
  442.         mov     bx,dx           ;bx has address in screen buffer
  443.         mov     cx,0            ;cx is  point counter
  444. ;figure out if slope is greater or less than 1
  445.         mov     dx,word ptr[bp+argbase+6]
  446.         cmp     dx,word ptr[bp+argbase+10]
  447.         jl      csteep
  448.         call    slant
  449.         jmp     finish
  450. csteep:
  451.         call    steep
  452. finish:
  453.         pop     si
  454.         pop     di
  455.         mov     sp,bp
  456.         pop     bp
  457.         ret        
  458.  
  459. pEnd _zline 
  460. slant    proc    near
  461.           ;slope<1
  462.         cmp     si,80      ;test for line off screen to right
  463.         jge     quit1
  464.         mov     di,word ptr[bp+argbase+10]
  465.         mov     dx,word ptr[bp+argbase+6]
  466.         mov     word ptr [bp-4],dx
  467.         shr     dx,1
  468.         mov     word ptr [bp-6],dx
  469.         mov     dx,3cfh
  470. newdot:
  471.         cmp     si,0       ;test for line off screen to left
  472.         jl      q1
  473.         out     dx,al                   ;output bit in byte to mask register
  474.         inc     byte ptr es:[bx][si]    ;insert byte in buffer ... note that 
  475.                         ;the inc instruction doesn't actually do the
  476.                         ;work -- it;s done by the EGA's wierd hardware
  477. q1:     ror     al,1            ;rotate bit in byte
  478.         jnc     nc1             ;test for shifting to next byte in screen 
  479.         inc     si              ;memory
  480.         cmp     si,80     
  481.         je      quit1
  482. nc1:    add     cx,di           ;this is the actual line algorithm
  483.         cmp     cx,word ptr [bp-6]  ;standard algorithm registerized for speed
  484.         jle     dcount
  485.         sub     cx,word ptr[bp+argbase+6]
  486.         add     bx,word ptr [bp-2]
  487. dcount: dec     word ptr [bp-4]
  488.         jge     newdot
  489. quit1:  ret
  490.  
  491.  
  492. slant    endp
  493. steep   proc    near
  494.         ;slope>1     see comments in "slant"
  495.         cmp     si,80
  496.         jge     quit2
  497.         mov     di,word ptr[bp+argbase+6]
  498.         or      di,di
  499.         je      vertical
  500.         mov     dx,word ptr[bp+argbase+10]
  501.         mov     word ptr[bp-4],dx
  502.         shr     dx,1
  503.         mov     word ptr[bp-6],dx
  504.         mov     dx,3cfh
  505.         out     dx,al
  506. newdot2:
  507.         cmp     si,0
  508.         jl      c3
  509.         inc     byte ptr es:[bx][si]
  510. c3:     add     bx,word ptr [bp-2]
  511.         add     cx,di
  512.         cmp     cx,word ptr[bp-6]
  513.         jle     dcount2
  514.         sub     cx,word ptr[bp+argbase+10]
  515.         ror     al,1
  516.         out     dx,al
  517.         jnc     dcount2
  518.         inc     si
  519.         cmp     si,80
  520.         je      quit2   
  521. dcount2:
  522.         dec     word ptr[bp-4]
  523.         jge     newdot2
  524. quit2:  ret
  525. vertical:
  526.         add     bx,si
  527.         cmp     si,0               ;special case for vertical lines
  528.         jl      quit2              ;which doesn't need fancy algorithm
  529.         mov     cx,word ptr[bp+argbase+10]
  530.         mov     dx,3cfh
  531.         out     dx,al
  532. loopy2: 
  533.         inc     byte ptr es:[bx]
  534. c3v:
  535.         add     bx,word ptr [bp-2]
  536.         dec     cx
  537.         jge     loopy2
  538.         ret
  539.  
  540.  
  541. steep   endp
  542.  
  543. ; setpal.asm routine to be called from c to set palete m to n
  544. ; setpal(m,n)  m=0 to 15, n 0 to 63
  545.  
  546.  
  547. pBegin  _setpal
  548.         push    bp  
  549.         mov     bp, sp
  550.         push    di
  551.         push    si
  552. ; Get arguments into registers
  553.         mov     bl, byte ptr [bp+argbase+4] 
  554.         mov     bh, byte ptr [bp+argbase+6] 
  555.         mov     al,0
  556.         mov     ah,16
  557.  
  558. ; Call BIOS
  559.         int     10H
  560.         pop     si
  561.         pop     di
  562.         pop     bp 
  563.         ret     
  564. pEnd _setpal
  565.  
  566. ;char colorlist[17]
  567. ;setpals(colorlist) causes all 16 palete registers and the border color   
  568. ;colorlist[16] to be set in one call. This uses the BIOS. 
  569.  
  570. ;pBegin _setpals
  571. ;        push    bp
  572. ;        mov     bp, sp
  573. ;ifdef NEARDATA
  574. ;        mov     dx, word ptr [bp+argbase+4] 
  575. ;        mov     ax,ds
  576. ;        mov     es,ax
  577. ;endif
  578. ;ifdef FARDATA
  579. ;        les     dx,[bp+argbase+4]
  580. ;endif
  581. ;        mov    al,2
  582. ;        mov    ah,16;
  583.  
  584. ; Call BIOS
  585. ;        int     10H
  586. ;        pop     bp   
  587. ;        ret
  588. ;pEnd    _setpals
  589.  
  590.  
  591. ;char colorlist[17]
  592. ;setpals(colorlist) causes all 16 palete registers and the border color   
  593. ;colorlist[16] to be set in one call. This is MUCH faster than the one
  594. ;using the IBM BIOS
  595.  
  596. pBegin _setpals
  597.         push    bp
  598.         mov     bp, sp
  599.         push    si
  600. ifdef NEARDATA
  601.         mov     bx, word ptr [bp+argbase+4] 
  602.         mov     ax,ds
  603.         mov     es,ax
  604. endif
  605. ifdef FARDATA
  606.         les     bx,[bp+argbase+4]
  607. endif
  608.         mov     dx,03dah
  609. spnvr:  in      al,dx ;wait for NOT vertical retrace
  610.         test    al,8
  611.         jnz     spnvr
  612. spvr:   in      al,dx ;wait for vertical retrace
  613.         test    al,8
  614.         jz      spvr
  615.         xor     si,si
  616.         mov     dx,03c0h
  617. sp2loop:
  618.         mov     ax,si
  619.         out     dx,al
  620.         mov     al,byte ptr es:[bx][si]
  621.         out     dx,al
  622.         inc     si
  623.         cmp     si,16
  624.         jne     sp2loop
  625.         mov     al,011h
  626.         out     dx,al
  627.         mov     al,byte ptr es:[bx][si]
  628.         out     dx,al
  629.         mov     al,020h
  630.         out     dx,al
  631.  
  632.         pop     si
  633.         pop     bp   
  634.         ret
  635. pEnd    _setpals
  636.  
  637.  
  638.  
  639. ;this routine resets the system to use ordinary bios or dos screen writes
  640. ;it has no parameters and may be called from any language
  641. pBegin _curmod
  642.         push    dx
  643.         push    ax
  644.  
  645.         mov     dx,3ceh                 ; change ENABLE SET/RESET register
  646.         mov     al,01h                  ; to disable SET/RESET feature
  647.         out     dx,al
  648.         mov     dx,3cfh
  649.         mov     al,00h
  650.         out     dx,al
  651.         mov     dx,3ceh                 ;set bit mask to enable all
  652.         mov     al,08h                  ;8 bits in a byte
  653.         out     dx,al
  654.         mov     dx,3cfh
  655.         mov     al,0ffh
  656.         out     dx,al
  657.  
  658.  
  659.         pop     ax
  660.         pop     dx
  661.         ret
  662. pEnd _curmod
  663.  
  664. ;         zpoint.asm plot point at xt,yt in color zpcol
  665. pBegin _zpoint
  666.         push    bp
  667.         mov     bp,sp
  668.  
  669.         mov     dx,3ceh                 ; change SET/RESET register
  670.         mov     al,00h                  ; to contain the color to write.
  671.         out     dx,al
  672.         mov     dx,3cfh
  673.         mov     al,byte ptr [bp+argbase+8]      ; <-- THIS IS THE COLOR.
  674.         out     dx,al
  675.         mov     ax,drawseg               ; segment of display buffer
  676.         mov     es,ax
  677.         mov     cx,word ptr [bp+argbase+4]      ; this is x value
  678.         mov     bx,cx
  679.         and     bx,7
  680.         sar     cx,1                     ;split x into bit and byte
  681.         sar     cx,1
  682.         sar     cx,1
  683.         or      cx,cx
  684.         jl      ptquit
  685.         cmp     cx,79
  686.         jg      ptquit
  687.  
  688.         mov     dx,3ceh 
  689.         mov     al,08h
  690.         out     dx,al                   ;set bit mask register
  691.         mov     dx,3cfh
  692.         mov     al,byte ptr btab[bx]
  693.         out     dx,al
  694.  
  695.         mov     bx,cx
  696.         mov     ax,word ptr [bp+argbase+6]         ;this is y value
  697.         mov     dx,ax
  698.         shl     dx,1
  699.         shl     dx,1
  700.         add     ax,dx
  701.         mov     cl,4
  702.         shl     ax,cl
  703.         add     bx,ax      
  704.         inc     byte ptr es:[bx]
  705.  
  706. ptquit: pop     bp
  707.         ret    
  708.  
  709. pEnd _zpoint
  710.  
  711.  
  712. pBegin _setmask 
  713. ;  set mask register     setmask(mask)
  714.  
  715.         push    bp
  716.         mov     bp,sp
  717.  
  718.         mov     cx,word ptr [bp+argbase+4]
  719.         mov     dx,03c4h
  720.         mov     al,2
  721.         out     dx,al
  722.         mov     dx,03c5h
  723.         mov     al,cl
  724.         out     dx,al
  725.         pop     bp
  726.         ret    
  727.  
  728.  
  729. pEnd _setmask
  730.  
  731.  
  732. ;_e_start start up ellipse plotter
  733. ; e_start(xleft,xright,y,color)
  734. pBegin _e_start 
  735.         push    bp
  736.         mov     bp,sp
  737.  
  738.         mov     dx,3ceh                ; change SET/RESET register
  739.         mov     al,00h                 ; to contain the color to write.
  740.         out     dx,al
  741.         mov     dx,3cfh
  742.         mov     al,byte ptr [bp+argbase+10]     ; <-- THIS IS THE COLOR.
  743.         out     dx,al
  744.         mov     ax,drawseg               ; segment of display buffer
  745.         mov     es,ax
  746.  
  747.         mov     cx,word ptr [bp+argbase+4]      ; this is left x value
  748.         mov     bx,cx
  749.         and     bx,7
  750.         sar     cx,1
  751.         sar     cx,1
  752.         sar     cx,1
  753.         mov     dx,3ceh           
  754.         mov     al,08h
  755.         out     dx,al
  756.         mov     dx,3cfh
  757.         mov     al,byte ptr btab[bx]
  758.         mov     leftbit,al
  759.  
  760.         out     dx,al
  761.  
  762.         mov     ax,word PTR [bp+argbase+8]  
  763.         mov     bx,ax
  764.         shl     ax,1
  765.         shl     ax,1
  766.         add     bx,ax
  767.         shl     bx,1
  768.         shl     bx,1
  769.         shl     bx,1
  770.         shl     bx,1
  771.         mov     ysave,bx
  772.         mov     leftx,cx
  773.         add     bx,cx
  774.         mov     leftbot,bx
  775.         mov     lefttop,bx
  776.         cmp     cx,80
  777.         jae     s1
  778.         inc     byte ptr es:[bx]
  779.  
  780. s1:     mov     cx,word ptr [bp+argbase+6]      ; this is right x value
  781.         mov     bx,cx
  782.         and     bx,7
  783.         sar     cx,1
  784.         sar     cx,1
  785.         sar     cx,1
  786.  
  787.         mov     dx,3cfh
  788.         mov     al,byte ptr btab[bx]
  789.         mov     rightbit,al
  790.         out     dx,al
  791.         mov     bx,ysave
  792.         mov     rightx,cx
  793.         add     bx,cx
  794.         mov     rightbot,bx
  795.         mov     righttop,bx
  796.         cmp     cx,80
  797.         jae     s2
  798.         inc     byte ptr es:[bx]
  799.  
  800. s2:     pop     bp
  801.         ret    
  802.  
  803. pEnd _e_start
  804.  
  805.  
  806. pBegin _e_xd
  807.         mov     ax,drawseg        
  808.         mov     es,ax
  809.         rol     rightbit,1
  810.         mov     al,rightbit
  811.         jae     l1  
  812.         dec     rightx      
  813.         dec     rightbot
  814.         dec     righttop        
  815. l1:     mov     dx,3cfh
  816.         out     dx,al
  817.         cmp     rightx,80
  818.         jae     s3
  819.         mov     bx,righttop
  820.         inc     byte ptr es:[bx]
  821.         mov     bx,rightbot
  822.         inc     byte ptr es:[bx]        
  823.  
  824. s3:     
  825.         ror     leftbit,1
  826.         mov     al,leftbit
  827.         jae     l2        
  828.         inc     leftx
  829.         inc     lefttop        
  830.         inc     leftbot
  831. l2:     out     dx,al
  832.         cmp     leftx,80
  833.         jae     s4
  834.         mov     bx,lefttop
  835.         inc     byte ptr es:[bx]
  836.         mov     bx,leftbot
  837.         inc     byte ptr es:[bx]        
  838. s4:     ret
  839. pEnd _e_xd 
  840.  
  841. pBegin _e_xdyu
  842.         mov     ax,drawseg           
  843.         mov     es,ax
  844.         rol     rightbit,1
  845.         mov     al,rightbit
  846.         jae     l3        
  847.         dec     rightx
  848.         dec     rightbot
  849.         dec     righttop        
  850. l3:     mov     dx,3cfh
  851.         out     dx,al
  852.         mov     cx,80
  853.         add     righttop,cx
  854.         sub     rightbot,cx
  855.         cmp     rightx,cx
  856.         jae     s5
  857.         mov     bx,righttop
  858.         inc     byte ptr es:[bx]
  859.         mov     bx,rightbot
  860.         inc     byte ptr es:[bx]        
  861.  
  862. s5:     
  863.         ror     leftbit,1
  864.         mov     al,leftbit
  865.         jae     l4        
  866.         inc     leftx
  867.         inc     lefttop        
  868.         inc     leftbot
  869. l4:     out     dx,al
  870.         add     lefttop,cx
  871.         sub     leftbot,cx
  872.         cmp     leftx,cx
  873.         jae     s6
  874.         mov     bx,lefttop
  875.         inc     byte ptr es:[bx]
  876.         mov     bx,leftbot
  877.         inc     byte ptr es:[bx]        
  878.  
  879.  
  880. s6:     ret
  881. pEnd _e_xdyu 
  882.  
  883. pBegin _e_yu
  884.         mov     ax,drawseg           
  885.         mov     es,ax
  886.         mov     al,leftbit
  887.         mov     dx,3cfh
  888.         out     dx,al
  889.         mov     cx,80
  890.         add     lefttop,cx
  891.         sub     leftbot,cx
  892.         cmp     leftx,cx
  893.         jae     s7
  894.         mov     bx,lefttop
  895.         inc     byte ptr es:[bx]
  896.         mov     bx,leftbot
  897.         inc     byte ptr es:[bx]        
  898. s7:     mov     al,rightbit
  899.         out     dx,al
  900.         add     righttop,cx
  901.         sub     rightbot,cx
  902.         cmp     rightx,cx
  903.         jae     s8
  904.         mov     bx,righttop
  905.         inc     byte ptr es:[bx]
  906.         mov     bx,rightbot
  907.         inc     byte ptr es:[bx]        
  908.  
  909. s8:     ret
  910. pEnd _e_yu 
  911.  
  912. pBegin _rectfill
  913. ;  rectfill(ix0,iy0,ix1,iy1,icol) plots a rectangle in 
  914. ; color icol.   all are integers
  915.         push    bp
  916.         mov     bp,sp
  917.         mov     bx,word PTR [bp+argbase+10]     ;bx has y1
  918.         cmp     bx,word ptr [bp+argbase+6]      ;compare with y0
  919.         jne     notflat
  920.         jmp     far ptr __horiz_
  921. notflat:
  922.         push    di
  923.         push    si
  924.         nop
  925.  
  926.         mov     dx,3ceh                 ; change SET/RESET register
  927.         mov     al,00h                  ; to contain the color to write.
  928.         out     dx,al
  929.         mov     dx,3cfh
  930.         mov     al,byte ptr [bp+argbase+12]     ; <-- THIS IS THE COLOR.
  931.         out     dx,al
  932.         mov     cx,word PTR [bp+argbase+4]      ;cx has x0
  933.         mov     dx,word PTR [bp+argbase+6]      ;dx has y0
  934.         mov     ax,word PTR [bp+argbase+8]      ;ax has x1
  935.  
  936.         cmp     ax,cx           ;make first point leftmost one
  937.         jge     test2
  938.         mov     si,ax
  939.         mov     ax,cx
  940.         mov     cx,si
  941. test2:  or      ax,ax
  942.         jge     test3
  943.         jmp     rfinish
  944. test3:  cmp     cx,640          ;clip to screen limits
  945.         jl      test4
  946.         jmp     rfinish
  947. test4:  cmp     cx,0
  948.         jge     test5
  949.         sub     cx,cx
  950. test5:  cmp     ax,640
  951.         jl      test6
  952.         mov     ax,639
  953. test6:
  954.         cmp     bx,dx
  955.         jge     test7
  956.         mov     si,bx
  957.         mov     bx,dx
  958.         mov     dx,si
  959. test7:  or      bx,bx
  960.         jge     test8
  961.         jmp     rfinish
  962. test8:  cmp     dx,maxline
  963.         jl      test9
  964.         jmp     rfinish
  965. test9:  cmp     dx,0
  966.         jge     testa
  967.         sub     dx,dx
  968. testa:  cmp     bx,maxline
  969.         jl      testb
  970.         mov     bx,maxline
  971.         dec     bx
  972. testb:  
  973.  
  974.         mov     xx0,cx
  975.         mov     yy0,dx
  976.         mov     xx1,ax
  977.         mov     yy1,bx
  978.  
  979.         mov     ax,cx                   ;calculate bte position in graphics
  980.         mov     dx,ax                   ;memory (x value)
  981.         and     dx,7
  982.         mov     cl,3
  983.         sar     ax,cl 
  984.         mov     xc10,ax                 ;byte value for leftmost point
  985.         mov     xc20,dx                 ;offset in byte
  986.         mov     di,ax
  987.         mov     ax,xx1
  988.         mov     dx,ax
  989.         and     dx,7
  990.         mov     cl,3
  991.         sar     ax,cl 
  992.         mov     xc11,ax                 ;byte value for rightmost byte
  993.         mov     xc21,dx                 ;offset in byte
  994.         sub     ax,di
  995.         mov     del_x,ax       
  996.         mov     ax,drawseg       
  997.         mov     es,ax
  998.         mov     dx,3ceh
  999.         mov     al,08h
  1000.         out     dx,al
  1001.  
  1002.         mov     ax,yy0           ; compute location of first byte to change
  1003.         mov     dx,ax            ; (y value) 
  1004.         shl     dx,1
  1005.         shl     dx,1
  1006.         add     ax,dx            ; mul by 80
  1007.         mov     cl,4
  1008.         shl     ax,cl
  1009.         add     ax,xc10
  1010.         mov     lowyb,ax
  1011.  
  1012.         mov     ax,yy1
  1013.         sub     ax,yy0
  1014.         inc     ax
  1015.         mov     del_y,ax        ;number of y lines
  1016.         mov     bx,xc20
  1017.         mov     dl,left[bx]
  1018.         or      del_x,0
  1019.         jnz     leftcol         ;if only one byte column, may need to mask
  1020.         mov     bx,xc21         ;right hand bits
  1021.         and     dl,right[bx]
  1022. leftcol:
  1023.         mov     al,dl
  1024.         mov     dx,3cfh        ;draw the entire left column of bytes
  1025.         out     dx,al          ;set bit mask register     
  1026.         mov     bx,lowyb
  1027.         mov     cx,del_y          
  1028.         mov     ax,80
  1029. loopd:  inc     byte ptr es:[bx]
  1030.         add     bx,ax
  1031.         loop    loopd          ;end of left column drawer
  1032.         cmp     del_x,1
  1033.         jl      rfinish
  1034.         jz      lastcol 
  1035.         mov     al,255
  1036.         out     dx,al          ;set mask register to all eight bits
  1037.         mov     bx,del_y
  1038.         mov     ax,lowyb
  1039.         inc     ax
  1040.         mov     si,del_x
  1041.         dec     si
  1042. loope:  mov     cx,si         ;draw the middle columns
  1043.         mov     di,ax
  1044.         rep     stosb
  1045.         add     ax,80
  1046.         dec     bx
  1047.         jnz     loope
  1048.  
  1049. lastcol:
  1050.         mov     bx,xc21      ;draw the right column
  1051.         mov     al,right[bx]
  1052.         out     dx,al          
  1053.         mov     bx,lowyb
  1054.         add     bx,del_x          
  1055.         mov     cx,del_y
  1056.         mov     ax,80
  1057. loopf:  inc     byte ptr es:[bx]
  1058.         add     bx,ax
  1059.         loop    loopf 
  1060.  
  1061. rfinish:
  1062.         pop     si
  1063.         pop     di
  1064.         pop     bp
  1065.         ret
  1066.  
  1067.  
  1068. pEnd _rectfill
  1069.  
  1070. pBegin __horiz_             ;stripped down version of rectfill
  1071.         push    di
  1072.         push    si
  1073.  
  1074.         mov     dx,word PTR [bp+argbase+6]      ;dx has y0
  1075.         cmp     dx,maxline      ;test for off screen verticallly
  1076.         jae     rfinish
  1077.         mov     dx,3ceh                 ; change SET/RESET register
  1078.         mov     al,00h                  ; to contain the color to write.
  1079.         out     dx,al
  1080.         mov     dx,3cfh
  1081.         mov     al,byte ptr [bp+argbase+12]     ; <-- THIS IS THE COLOR.
  1082.         out     dx,al
  1083.         mov     cx,word PTR [bp+argbase+4]      ;cx has x0
  1084.         mov     bx,word PTR [bp+argbase+8]      ;bx has x1
  1085.  
  1086.         cmp     bx,cx
  1087.         jge     test2h
  1088.         mov     si,bx
  1089.         mov     bx,cx
  1090.         mov     cx,si
  1091. test2h: or      bx,bx         ;clip to screen
  1092.         jge     test3h
  1093.         jmp     hfinish
  1094. test3h: cmp     cx,640
  1095.         jl      test4h
  1096.         jmp     hfinish
  1097. test4h: cmp     cx,0
  1098.         jge     test5h
  1099.         sub     cx,cx
  1100. test5h: cmp     bx,640
  1101.         jl      test6h
  1102.         mov     bx,639
  1103. test6h:
  1104.  
  1105.         xor     dx,dx 
  1106.         mov     ax,cx
  1107.         div     ate
  1108.         mov     xc10,ax                 ;byte value
  1109.         mov     xc20,dx                 ;offset in byte
  1110.         mov     cx,ax
  1111.         xor     dx,dx      
  1112.         mov     ax,bx
  1113.         div     ate
  1114.         mov     xc11,ax
  1115.         mov     xc21,dx
  1116.         sub     ax,cx
  1117.         mov     cx,ax       
  1118.         mov     ax,drawseg       
  1119.         mov     es,ax
  1120.         mov     dx,3ceh
  1121.         mov     al,08h
  1122.         out     dx,al
  1123.  
  1124.                             ; compute location of byte to change
  1125.         mov     ax,word ptr [bp+argbase+6]
  1126.         mov     dx,ax
  1127.         shl     dx,1
  1128.         shl     dx,1
  1129.         add     ax,dx
  1130.         shl     ax,1
  1131.         shl     ax,1
  1132.         shl     ax,1
  1133.         shl     ax,1
  1134.         add     ax,xc10
  1135.         mov     di,ax
  1136.  
  1137.         mov     bx,xc20
  1138.         mov     al,left[bx]
  1139.         or      cx,cx
  1140.         jnz     leftcoh         
  1141.         mov     bx,xc21          
  1142.         and     al,right[bx]
  1143. leftcoh:
  1144.         mov     dx,3cfh
  1145.         out     dx,al     
  1146.         inc     byte ptr es:[di]
  1147.         inc     di
  1148.         cmp     cx,1
  1149.         jl      hfinish
  1150.         jz      lastcoh 
  1151.         mov     al,255
  1152.         out     dx,al
  1153.         dec     cx
  1154.         rep     stosb
  1155.  
  1156. lastcoh:
  1157.         mov     bx,xc21
  1158.         mov     al,right[bx]
  1159.         out     dx,al          
  1160.         inc     byte ptr es:[di]
  1161.  
  1162. hfinish:
  1163.         pop     si
  1164.         pop     di
  1165.         pop     bp
  1166.         ret
  1167.  
  1168. pEnd __horiz_
  1169. ;setdraw(i)  sets drawing buffer to i  i = 0 or 1
  1170.  
  1171. pBegin _setdraw       
  1172.  
  1173.         push    bp
  1174.         mov     bp,sp
  1175.         mov     cx, word ptr [bp+argbase+4]     
  1176.         mov     ax,0a000h
  1177. loopds:
  1178.         cmp     cx,0
  1179.         jz      ds1
  1180.         add     ax,0800h
  1181.         cmp     maxline,480
  1182.         jnz     ds1
  1183.         add     ax,0800h
  1184. ds1:    mov     drawseg,ax
  1185.         pop     bp              
  1186.         ret
  1187.  
  1188. pEnd _setdraw
  1189.  
  1190. ;setdisp(i) sets the displayed segment to i = 0 or 1 
  1191. pBegin _setdisp       
  1192.  
  1193.         push    bp
  1194.         mov     bp,sp
  1195.         mov     ax, word ptr [bp+argbase+4]     
  1196.  
  1197.         mov     ah,5
  1198.         int     010h
  1199.         pop     bp              
  1200.         ret
  1201.  
  1202. pEnd _setdisp
  1203.  
  1204. endcs _egagraf
  1205.       end
  1206.  
  1207. **************end file EGAGRA.ASM**************
  1208. **************begin file MACROS.AH*************
  1209.  
  1210.   SMALL equ 1
  1211.  
  1212. ;
  1213. ; break down modules
  1214. ;
  1215. ifdef SMALL
  1216.   NEARDATA equ 1
  1217.   NEARCODE equ 1
  1218. endif
  1219.  
  1220. ifdef COMPACT
  1221.    FARDATA equ 1
  1222.   NEARCODE equ 1
  1223. endif
  1224.  
  1225. ifdef MEDIUM
  1226.   NEARDATA equ 1
  1227.    FARCODE equ 1
  1228. endif
  1229.  
  1230. ifdef LARGE
  1231.    FARDATA equ 1
  1232.    FARCODE equ 1
  1233. endif
  1234.  
  1235. ;
  1236. ; define model-dependent parameters
  1237. ;
  1238.  
  1239. ifdef NEARCODE
  1240.   argbase equ 0
  1241. endif
  1242.  
  1243. ifdef FARCODE
  1244.   argbase equ 2
  1245. endif
  1246.  
  1247. ;
  1248. ; macros
  1249. ;
  1250.  
  1251. cseg    macro moduleName
  1252.     ifdef FARCODE
  1253.       moduleName&_TEXT segment byte public 'CODE'
  1254.       assume cs: moduleName&_TEXT
  1255.     else
  1256.       _TEXT segment byte public 'CODE'
  1257.       assume cs: _TEXT
  1258.     endif
  1259.     endm
  1260.  
  1261. endcs    macro moduleName
  1262.     ifdef FARCODE
  1263.       moduleName&_TEXT ends
  1264.     else
  1265.       _TEXT ends
  1266.     endif
  1267.     endm
  1268.  
  1269. pBegin    macro pName
  1270.     ifdef FARCODE
  1271.       pName proc far
  1272.     else
  1273.       pName proc near
  1274.     endif
  1275.         public pName
  1276.     endm
  1277.  
  1278. pEnd    macro pName
  1279.     pName endp
  1280.     endm
  1281.  
  1282.  
  1283. ****************end file MACROS.AH*************
  1284. ****************begin file EGAFORT.H***********
  1285. $notruncate
  1286.       interface to subroutine slettr[c](ix,iy,ichr,icol)
  1287.       integer*2 ix,iy,ichr,icol
  1288.       end
  1289.  
  1290.       interface to subroutine symbol[c]
  1291.      1            (ix,iy,height,icol,symb[reference])
  1292.       integer*2 ix,iy,height,icol
  1293.       integer*1 symb(8)
  1294.       end
  1295.  
  1296.       interface to subroutine llettr[c](ix,iy,ichr,icol)
  1297.       integer*2 ix,iy,ichr,icol
  1298.       end
  1299.  
  1300.       interface to subroutine setmod[c](n)
  1301.       integer*2 n
  1302.       end
  1303.  
  1304.       interface to subroutine setdraw[c](n)
  1305.       integer*2 n
  1306.       end
  1307.  
  1308.       interface to subroutine setdisp[c](n)
  1309.       integer*2 n
  1310.       end
  1311.  
  1312.       interface to subroutine zsetup[c]()
  1313.       end
  1314.  
  1315.  
  1316.       interface to subroutine zline[c](ix0, iy0, ix1, iy1, icol)
  1317.       integer*2 ix0, iy0, ix1, iy1, icol
  1318.       end
  1319.  
  1320.       interface to subroutine clipline[c](ix0, iy0, ix1, iy1,
  1321.      1    icol)
  1322.       integer*2 ix0, iy0, ix1, iy1, icol
  1323.       end
  1324.  
  1325.       interface to subroutine setpal[c](ipal, icol)
  1326.       integer*2 ipal, icol
  1327.       end
  1328.  
  1329.       interface to subroutine setpals[c](palete[reference])
  1330.       integer*1 palete(17)
  1331.       end
  1332.  
  1333.       interface to subroutine curmod[c]()
  1334.       end
  1335.  
  1336.       interface to subroutine zpoint[c](ix, iy, icol)
  1337.       integer*2 ix, iy, icol
  1338.       end
  1339.  
  1340.       interface to subroutine setmask[c](mask)
  1341.       integer*2 mask
  1342.       end
  1343.  
  1344.       interface to subroutine rectfill[c](ix0, iy0, ix1, iy1, icol)
  1345.       integer*2 ix0, iy0, ix1, iy1, icol
  1346.       end
  1347.  
  1348.       interface to subroutine ellipse[c](ix0, iy0, irx, iry, icol)
  1349.       integer*2 ix0, iy0, irx, iry, icol
  1350.       end
  1351.  
  1352.       interface to subroutine fillelip[c](ix0, iy0, irx, iry, icol)
  1353.       integer*2 ix0, iy0, irx, iry, icol
  1354.       end
  1355.  
  1356. *************end file EGAFORT.H*****************
  1357.